package org.example;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;

import java.util.UUID;
import java.util.concurrent.TimeUnit;

/**
 * Hello world!
 */
public class AppLogback {

    static {
        System.out.println("静态方法.开始加载logback.xml");
        System.setProperty("LOG_PATH", "F:/BaiduNetdiskDownload/mylog/");
    }

    private static final Logger logger = LoggerFactory.getLogger(AppLogback.class);

    public static void main(String[] args) throws Exception {

//        LOG_PATH

        // main 方法中
//        System.setProperty("LOG_PATH", "F:/BaiduNetdiskDownload/mylog/");

        TimeUnit.SECONDS.sleep(5);

        System.out.println("LOG_PATH="+System.getProperty("LOG_PATH"));

        for (int i = 1; i <= 3; i++) {

            new Thread(
                    new Runnable() {
                        @Override
                        public void run() {

                            MDC.clear();
                            MDC.put("TRACE_LOG_ID", UUID.randomUUID().toString());
                            MDC.put("dstTraceId", "messagePlatform:" + UUID.randomUUID().toString());

                            while (true) {
                                logger.trace("trace-------111111-----");
                                logger.debug("debug------111111111------");
                                logger.info("info------1111111111------");
                                logger.warn("warn-----1111111111-------");
                                logger.error("error-----111111111-------");

                                try {
                                    TimeUnit.SECONDS.sleep(1);
                                } catch (InterruptedException e) {
                                    throw new RuntimeException(e);
                                }
                            }
                        }
                    }
                    , "LogThead_" + i).start();
        }

        System.out.println("程序结束了");

    }
}
